package o;

import android.annotation.SuppressLint;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.ViewTreeObserver.OnPreDrawListener;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.core.view.ViewCompat;
import o.nn.c;

@SuppressLint({"ViewConstructor"})
class nd extends View implements nf {
    private int ʻ;
    private final OnPreDrawListener ʼ = new OnPreDrawListener(this) {
        final /* synthetic */ nd ˏ;

        {
            this.ˏ = r1;
        }

        public boolean onPreDraw() {
            this.ˏ.ॱ = this.ˏ.ˋ.getMatrix();
            ViewCompat.ˎ(this.ˏ);
            if (!(this.ˏ.ˏ == null || this.ˏ.ˊ == null)) {
                this.ˏ.ˏ.endViewTransition(this.ˏ.ˊ);
                ViewCompat.ˎ(this.ˏ.ˏ);
                this.ˏ.ˏ = null;
                this.ˏ.ˊ = null;
            }
            return true;
        }
    };
    View ˊ;
    final View ˋ;
    int ˎ;
    ViewGroup ˏ;
    Matrix ॱ;
    private final Matrix ॱॱ = new Matrix();
    private int ᐝ;

    static nf ॱ(View view, ViewGroup viewGroup) {
        nf ˊ = ˊ(view);
        if (ˊ == null) {
            FrameLayout ॱ = ॱ(viewGroup);
            if (ॱ == null) {
                return null;
            }
            ˊ = new nd(view);
            ॱ.addView(ˊ);
        }
        ˊ.ˎ++;
        return ˊ;
    }

    static void ॱ(View view) {
        View ˊ = ˊ(view);
        if (ˊ != null) {
            ˊ.ˎ--;
            if (ˊ.ˎ <= 0) {
                ViewParent parent = ˊ.getParent();
                if (parent instanceof ViewGroup) {
                    ViewGroup viewGroup = (ViewGroup) parent;
                    viewGroup.endViewTransition(ˊ);
                    viewGroup.removeView(ˊ);
                }
            }
        }
    }

    private static FrameLayout ॱ(ViewGroup viewGroup) {
        ViewGroup viewGroup2 = viewGroup;
        while (!(viewGroup2 instanceof FrameLayout)) {
            ViewParent parent = viewGroup2.getParent();
            if (!(parent instanceof ViewGroup)) {
                return null;
            }
            viewGroup2 = (ViewGroup) parent;
        }
        return (FrameLayout) viewGroup2;
    }

    nd(View view) {
        super(view.getContext());
        this.ˋ = view;
        setLayerType(2, null);
    }

    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        ˋ(this.ˋ, this);
        int[] iArr = new int[2];
        int[] iArr2 = new int[2];
        getLocationOnScreen(iArr);
        this.ˋ.getLocationOnScreen(iArr2);
        iArr2[0] = (int) (((float) iArr2[0]) - this.ˋ.getTranslationX());
        iArr2[1] = (int) (((float) iArr2[1]) - this.ˋ.getTranslationY());
        this.ʻ = iArr2[0] - iArr[0];
        this.ᐝ = iArr2[1] - iArr[1];
        this.ˋ.getViewTreeObserver().addOnPreDrawListener(this.ʼ);
        this.ˋ.setVisibility(4);
    }

    protected void onDetachedFromWindow() {
        this.ˋ.getViewTreeObserver().removeOnPreDrawListener(this.ʼ);
        this.ˋ.setVisibility(0);
        ˋ(this.ˋ, null);
        super.onDetachedFromWindow();
    }

    protected void onDraw(Canvas canvas) {
        this.ॱॱ.set(this.ॱ);
        this.ॱॱ.postTranslate((float) this.ʻ, (float) this.ᐝ);
        canvas.setMatrix(this.ॱॱ);
        this.ˋ.draw(canvas);
    }

    public void setVisibility(int i) {
        super.setVisibility(i);
        this.ˋ.setVisibility(i == 0 ? 4 : 0);
    }

    public void ˏ(ViewGroup viewGroup, View view) {
        this.ˏ = viewGroup;
        this.ˊ = view;
    }

    private static void ˋ(@NonNull View view, nd ndVar) {
        view.setTag(c.ˊ, ndVar);
    }

    static nd ˊ(@NonNull View view) {
        return (nd) view.getTag(c.ˊ);
    }
}
